package cn.yangliu.nacos.gateway.repository;

import java.util.List;

import cn.yangliu.nacos.gateway.entity.Oauth2ClientAuthority;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/**
 * The type of nacos.
 *
 * @author 问道于盲
 * @date 2020 -01-01
 */
public interface Oauth2ClientAuthorityRepository extends JpaRepository<Oauth2ClientAuthority,Long> {

    /**
     * Find oauth 2 client authorities by client id list.
     *
     * @param clientId the client id
     * @return the list
     */
    @Query("from Oauth2ClientAuthority a " +
            "inner join Oauth2ClientRole2Authority r2a on(r2a.id.authorityId = a.id) " +
            "inner join Oauth2ClientRole r on(r.id = r2a.id.roleId) " +
            "inner join Oauth2ClientClient2Role c2r on(c2r.id.roleId = r.id) " +
            "inner join Oauth2Client c on(c.id = c2r.id.clientId) " +
            "where c.clientId = :clientId")
    List<Oauth2ClientAuthority> findOauth2ClientAuthoritiesByClientId(String clientId);
}
